load("@fbcode_macros//build_defs:cpp_binary.bzl", "cpp_binary")
load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library")

oncall("scm_client_infra")

EDEN_STORE_UTIL_SRCS = ["eden_store_util.cpp"]

cpp_binary(
    name = "eden_store_util",
    srcs = EDEN_STORE_UTIL_SRCS,
    compatible_with = [
        "ovr_config//os:linux",
        "ovr_config//os:macos",
    ],
    deps = [
        ":rocksdb",
        ":store",
        "//eden/common/telemetry:structured_logger",
        "//eden/common/utils:fault_injector",
        "//eden/common/utils:user_info",
        "//eden/fs/config:config",
        "//eden/fs/service:init",
        "//eden/fs/service:server",
        "//eden/fs/telemetry:stats",
        "//folly:range",
        "//folly:stop_watch",
        "//folly:string",
        "//folly/container:array",
        "//folly/container:enumerate",
        "//folly/init:init",
        "//folly/logging:init",
        "//folly/logging:logging",
    ],
)

ROCKSDB_SRCS = ["RocksDbLocalStore.cpp"]

ROCKSDB_HEADERS = ["RocksDbLocalStore.h"]

cpp_library(
    name = "rocksdb",
    srcs = ROCKSDB_SRCS,
    headers = ROCKSDB_HEADERS,
    deps = [
        "//eden/common/telemetry:structured_logger",
        "//eden/common/utils:bug",
        "//eden/common/utils:fault_injector",
        "//eden/common/utils:throw",
        "//eden/fs/config:config",
        "//eden/fs/telemetry:log_info",
        "//eden/fs/telemetry:stats",
        "//eden/fs/telemetry:task_trace",
        "//fb303:service_data",
        "//folly:string",
        "//folly/futures:core",
        "//folly/logging:logging",
        "//rocksdb:rocksdb",
    ],
    exported_deps = [
        ":store",
        "//eden/common/utils:utils",
        "//eden/fs/rocksdb:rocksdb",
        "//folly:cpp_attributes",
        "//folly:synchronized",
    ],
)

SQLITE_SRCS = ["SqliteLocalStore.cpp"]

SQLITE_HEADERS = ["SqliteLocalStore.h"]

cpp_library(
    name = "sqlite",
    srcs = SQLITE_SRCS,
    headers = SQLITE_HEADERS,
    deps = [
        "//eden/fs/telemetry:stats",
        "//folly/container:array",
    ],
    exported_deps = [
        ":store",
        "//eden/fs/sqlite:sqlite",
        "//folly:synchronized",
    ],
)

CONTEXT_SRCS = [
    "ObjectFetchContext.cpp",
    "StatsFetchContext.cpp",
    "ImportPriority.cpp",
]

CONTEXT_HEADERS = [
    "ObjectFetchContext.h",
    "StatsFetchContext.h",
    "ImportPriority.h",
]

cpp_library(
    name = "context",
    srcs = CONTEXT_SRCS,
    headers = CONTEXT_HEADERS,
    deps = [
        "//folly:cpp_attributes",
        "//folly/logging:logging",
    ],
    exported_deps = [
        "fbsource//third-party/fmt:fmt",
        "//eden/common/os:os",
        "//eden/common/utils:ref_ptr",
        "//eden/fs/telemetry:stats",
    ],
)

BACKING_STORE_TYPE_INF = ["BackingStoreType.h"]

BACKING_STORE_TYPE_SRCS = ["BackingStoreType.cpp"]

cpp_library(
    name = "store_type",
    srcs = BACKING_STORE_TYPE_SRCS,
    headers = BACKING_STORE_TYPE_INF,
    deps = [
        "//eden/common/utils:throw",
    ],
)

BACKING_STORE_INF = ["BackingStore.h"]

cpp_library(
    name = "backing_store_interface",
    headers = BACKING_STORE_INF,
    exported_deps = [
        ":context",
        ":store_type",
        "//eden/common/utils:immediate_future",
        "//eden/common/utils:path",
        "//eden/fs/model:model",
        "//eden/fs/model:model-fwd",
        "//folly:range",
        "//folly/coro:task",
        "//folly/futures:core",
        "//folly/memory:not_null",
    ],
)

FILTERED_BACKING_STORE_HEADERS = ["FilteredBackingStore.h"]

FILTERED_BACKING_STORE_SRCS = ["FilteredBackingStore.cpp"]

cpp_library(
    name = "filtered_backing_store",
    srcs = FILTERED_BACKING_STORE_SRCS,
    headers = FILTERED_BACKING_STORE_HEADERS,
    deps = [
        "//eden/common/utils:immediate_future",
        "//eden/fs/config:config",
        "//eden/fs/model:model",
        "//eden/fs/store/hg:sapling_backing_store",
        "//eden/fs/utils:filter_utils",
        "//folly:varint",
    ],
    exported_deps = [
        "fbsource//third-party/googletest:gtest",
        ":backing_store_interface",
        "//eden/common/utils:ref_ptr",
        "//eden/common/utils:utils",
        "//eden/fs/store/filter:filtered_object_id",
        "//eden/fs/store/filter:filters",
        "//folly/coro:task",
    ],
)

cpp_library(
    name = "store",
    srcs = glob(
        ["*.cpp"],
        exclude = EDEN_STORE_UTIL_SRCS + ROCKSDB_SRCS + SQLITE_SRCS + CONTEXT_SRCS + FILTERED_BACKING_STORE_SRCS + BACKING_STORE_TYPE_SRCS,
    ),
    headers = glob(
        ["*.h"],
        exclude = ROCKSDB_HEADERS + SQLITE_HEADERS + CONTEXT_HEADERS + BACKING_STORE_INF + FILTERED_BACKING_STORE_HEADERS + BACKING_STORE_TYPE_INF,
    ),
    deps = [
        "//eden/common/telemetry:structured_logger",
        "//eden/common/utils:bug",
        "//eden/common/utils:hash",
        "//eden/common/utils:process_info_cache",
        "//eden/common/utils:throw",
        "//eden/fs/model/git:git",
        "//eden/fs/model/git:gitignore",
        "//eden/fs/telemetry:log_info",
        "//eden/fs/telemetry:task_trace",
        "//eden/fs/utils:eden_error",
        "//fb303:service_data",
        "//folly:conv",
        "//folly:exception_wrapper",
        "//folly:portability",
        "//folly:string",
        "//folly:varint",
        "//folly/io:iobuf",
        "//folly/lang:bits",
    ],
    exported_deps = [
        "fbsource//third-party/googletest:gtest",
        ":backing_store_interface",
        ":context",
        "//eden/common/utils:case_sensitivity",
        "//eden/common/utils:immediate_future",
        "//eden/common/utils:path",
        "//eden/common/utils:ref_ptr",
        "//eden/common/utils:utils",
        "//eden/fs/config:config",
        "//eden/fs/journal:journal",
        "//eden/fs/model:model",
        "//eden/fs/model:model-fwd",
        "//eden/fs/service:thrift-cpp2-types",
        "//eden/fs/telemetry:stats",
        "//eden/fs/utils:sharded_lru_cache",
        "//folly:cancellation_token",
        "//folly:executor",
        "//folly:intrusive_list",
        "//folly:map_util",
        "//folly:range",
        "//folly:synchronized",
        "//folly/container:evicting_cache_map",
        "//folly/container:f14_hash",
        "//folly/coro:task",
        "//folly/futures:core",
        "//folly/futures:shared_promise",
        "//folly/logging:logging",
        "//folly/synchronization:distributed_mutex",
    ],
)
